package interfaceGrafica;

import java.util.HashMap;
import java.util.Hashtable;

import InterFaceContact.Link;
import InterFaceContact.Request;
import InterFaceContact.Trafic;

import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxStylesheet;


public class AdicionarGrafo extends Acoes {

	static int x = 200;
	static int y = 30;
	
	public AdicionarGrafo(String nome) {
		this.getGraph().getModel().beginUpdate();
		Object parent = this.getGraph().getDefaultParent();
		
		mxStylesheet stylesheet = graph.getStylesheet();
		Hashtable<String, Object> style = new Hashtable<String, Object>();
		style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_DOUBLE_ELLIPSE);
		style.put(mxConstants.STYLE_OPACITY, 50);
		style.put(mxConstants.STYLE_FONTCOLOR, "#000000");
		stylesheet.putCellStyle("ROUNDED", style);
		
		Object v1 = this.getGraph().insertVertex(parent, null, nome, x, y, 40, 35,"ROUNDED;stylesheet");
		this.getM().put(nome, v1);
		if(topologia.containsKey(nome)){
			nome = null;
		}else{
			topologia.put(nome, new HashMap<String, Link>());
		}
		this.getGraph().getModel().endUpdate();
		
		if(x >= 500){
			y = y + 25;
			x = 45;
		}else{
			x = x + 45;
		}
	}
	
	public AdicionarGrafo(String nome, double posX, double posY) {
		this.getGraph().getModel().beginUpdate();
		Object parent = this.getGraph().getDefaultParent();
		
		mxStylesheet stylesheet = graph.getStylesheet();
		Hashtable<String, Object> style = new Hashtable<String, Object>();
		style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_DOUBLE_ELLIPSE);
		style.put(mxConstants.STYLE_OPACITY, 50);
		style.put(mxConstants.STYLE_FONTCOLOR, "#000000");
		stylesheet.putCellStyle("ROUNDED", style);
		
		Object v1 = this.getGraph().insertVertex(parent, null, nome, posX, posY, 40, 35,"ROUNDED;stylesheet");
		this.getM().put(nome, v1);
		if(topologia.containsKey(nome)){
			nome = null;
		}else{
			topologia.put(nome, new HashMap<String, Link>());
		}
		
		this.getGraph().getModel().endUpdate();
	}
	
}
